/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package qlvbdq.dao;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.ArrayList;
import qlvbdq.dconnection.SQLServerConnect;
import qlvbdq.dto.CTPhieuGiaCongDTO;

/**
 *
 * @author tuan
 */
public class CTPhieuGiaCongDAO {

    public CTPhieuGiaCongDAO() {
    }
    
    public ArrayList<CTPhieuGiaCongDTO> getCTPhieuGCByMaPhieuGC(String MaPhieuGC) throws SQLException {
        Object[] objs = { MaPhieuGC };
        ResultSet rs = SQLServerConnect.getInstance().getDataFromStore("GetCTPhieuGCByMaPhieuFromDatabase(?)", objs);
        ArrayList<CTPhieuGiaCongDTO> listCTPGC = new ArrayList<>();
        CTPhieuGiaCongDTO ctPGC;
        while (rs.next()) {
            ctPGC = new CTPhieuGiaCongDTO(rs.getString("MAPHIEUGC"), rs.getString("MAHANGGC"), rs.getInt("SOLUONG"), rs.getLong("THANHTIEN"));
            listCTPGC.add(ctPGC);
        }
        return listCTPGC;
    }
    
    public CTPhieuGiaCongDTO getCTPhieuGCByMaPhieuGCMaHGC(CTPhieuGiaCongDTO ctPhieuGC) throws SQLException {
        Object[] objs = { ctPhieuGC.getMaPhieuGC(), ctPhieuGC.getMaHangGC() };
        ResultSet rs = SQLServerConnect.getInstance().getDataFromStore("GetCTPhieuGCByMaPhieuMaHGCFromDatabase(?, ?)", objs);
        
        CTPhieuGiaCongDTO ctPGC = null;
        while (rs.next()) {
            ctPGC = new CTPhieuGiaCongDTO(rs.getString("MAPHIEUGC"), rs.getString("MAHANGGC"), rs.getInt("SOLUONG"), rs.getLong("THANHTIEN"));
            
        }
        return ctPGC;
    }
    
    public int insertCTPhieuGC(CTPhieuGiaCongDTO ctPhieuGC) {
        Object[] objs = { ctPhieuGC.getMaPhieuGC(), ctPhieuGC.getMaHangGC(), ctPhieuGC.getSoLuong(), ctPhieuGC.getThanhTien() };
        return SQLServerConnect.getInstance().updateDataToDatabase("InsertCTPHIEUGIACONGFromDataBase(?, ?, ?, ?)", objs);
    }
    
    public int deleteCTPhieuGCByMaPhieuGC(CTPhieuGiaCongDTO ctPhieuGC) {
        Object[] objs = { ctPhieuGC.getMaPhieuGC() };
        return SQLServerConnect.getInstance().updateDataToDatabase("DeleteCTPhieuGCByMaPhieuGCToDatabase(?)", objs);
    }
    
    public int deleteCTPhieuGCByMaPhieuGCMaHangGC(CTPhieuGiaCongDTO ctPhieuGC) {
        Object[] objs = { ctPhieuGC.getMaPhieuGC(), ctPhieuGC.getMaHangGC() };
        return SQLServerConnect.getInstance().updateDataToDatabase("DeleteCTPhieuGCByMaPhieuGCMaHGCToDatabase(?, ?)", objs);
    }
}
